Adding vector graphics to the web 您所在的位置:网站首页 How to Use SVG Images in CSS and HTML Adding vector graphics to the web

Adding vector graphics to the web

2024-06-03 08:20| 来源: 网络整理| 查看: 265

SVG is an XML-based language for describing vector images. It's basically markup, like HTML, except that you've got many different elements for defining the shapes you want to appear in your image, and the effects you want to apply to those shapes. SVG is for marking up graphics, not content. SVG defines elements for creating basic shapes, like and , as well as elements for creating more complex shapes, like and . More advanced SVG features include (transform colors using a transformation matrix), (animate parts of your vector graphic), and (apply a mask over the top of your image).

As a basic example, the following code creates a circle and a rectangle:

html

This creates the following output:

From the example above, you may get the impression that SVG is easy to hand code. Yes, you can hand code simple SVG in a text editor, but for a complex image this quickly starts to get very difficult. For creating SVG images, most people use a vector graphics editor like Inkscape or Illustrator. These packages allow you to create a variety of illustrations using various graphics tools, and create approximations of photos (for example Inkscape's Trace Bitmap feature.)

SVG has some additional advantages besides those described so far:

Text in vector images remains accessible (which also benefits your SEO). SVGs lend themselves well to styling/scripting, because each component of the image is an element that can be styled via CSS or scripted via JavaScript.

So why would anyone want to use raster graphics over SVG? Well, SVG does have some disadvantages:

SVG can get complicated very quickly, meaning that file sizes can grow; complex SVGs can also take significant processing time in the browser. SVG can be harder to create than raster images, depending on what kind of image you are trying to create.

Raster graphics are arguably better for complex precision images such as photos, for the reasons described above.

Note: In Inkscape, save your files as Plain SVG to save space. Also, please refer to this article describing how to prepare SVGs for the Web.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有